package com.test;

import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TSimpleServer;
import org.apache.thrift.transport.TServerSocket;

/**
 * HelloServer
 *
 * @author longhuashen
 * @since 2023/11/10
 */
public class HelloServer {

    public static final int SERVER_PORT = 8090;

    public void startServer(){
        System.out.println("Server is Runing......");

        TProcessor tprocessor = new HelloWorldService.Processor(new HelloWorldImpl());
        //简单的单线程服务模型，一般用于测试
        try {
            TServerSocket serverTransport = new TServerSocket(SERVER_PORT);
            TServer.Args tArgs = new TServer.Args(serverTransport);
            tArgs.processor(tprocessor);
            tArgs.protocolFactory(new TBinaryProtocol.Factory());
            TServer server = new TSimpleServer(tArgs);
            server.serve();

        } catch (Exception e) {
            System.out.println("Server start error！");
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        HelloServer server = new HelloServer();
        server.startServer();
    }
}
